package com.ext.portlet.registration.service.impl;

import com.ext.portlet.registration.model.School;
import com.ext.portlet.registration.service.base.SchoolServiceBaseImpl;
import com.liferay.portal.PortalException;
import com.liferay.portal.SystemException;
import com.liferay.portal.kernel.util.Validator;
import com.liferay.portal.model.Group;
import com.liferay.portal.service.GroupServiceUtil;


public class SchoolServiceImpl extends SchoolServiceBaseImpl {
	
	public String validateSchooName(String schoolName, Long companyId) throws  PortalException, SystemException {
	
		String name = null;
		School school = null;
		
		school = schoolPersistence.fetchByName(schoolName);
		
		if(Validator.isNotNull(school)){
			
			name = school.getName();
			
		}else {
			
			Group group = GroupServiceUtil.getGroup(companyId, schoolName);
			
			if(Validator.isNotNull(group)) {
				
				name = group.getName();
			}
		}
		
		return name;
	}
}
